#include <iostream>
#include <stdlib.h>

using namespace std;

#define Maxsize 0xffff  // FIXME: 宏定义最好是全部大写 MAXSIZE, or MAX_SIZE

template <class type>
class my_stack
{

public:
    my_stack():top(-1),maxsize(Maxsize)
    {
        my_sta=new type[maxsize];

        if(my_sta==NULL)
        {cout<<"error the dynamic story divide fail"<<endl;
        exit(1);
        }
    }

    my_stack(int size):top(-1),maxsize(Masize)
    {
        my_sta=new type[maxsize];
        if(my_sta==NULL)
        {
            cout<<"error,dynamic story divide fail"<<endl;
            exit(1);
        }
    }

    ~my_stack()
    {
        delete[] my_sta;
    }

    bool empty();
    void Push(type tp);
    type Top();
    void Pop();
    int size();

private:
   int top;
   type* my_sta;
   int maxsize;
};

template<class type>
bool my_stack<type>::empty()
{
    if(top==-1)        return true;
else
    return false;
    }

template<class type>
type my_stack<type>::Top()
{
    if(top!=-1)
    {
        return my_sta[top];
    }
    else
    {
        cout<<"an empty stack"<<endl;
        exit(1);
    }
}

template<class type>
void my_stack<type>::Push(type tp)
{
    if(top+1<maxsize)
    {
        my_sta[++top]=tp;
    }
    else
    {
        cout<<"an full stack"<<endl;
        exit(1);
    }
}

template<class type>
void my_stack<type>::Pop()
{
    if(top>=0)
    {
        my_sta[top]=0;
        top--;
    }
    else
    {
        cout<<"an empty stack"<<endl;
        exit(1);
    }
}

template<class type>
int my_stack<type>::size()
{
    return top+1;
}

